package com.mengtian_tech.tju.dataquery.api.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import com.mengtian_tech.tju.dataquery.api.db.EnhancedJdbcTemplate;

@Configuration
public class DataSourceConfig {

	/** OA数据源	 */
	@Bean(name = "dataSourceOA")
	@ConfigurationProperties("spring.datasource.druid.oa")
	public DataSource dataSourceOA() {
		System.out.println("config data source");
		return DruidDataSourceBuilder.create().build();
	}

	/** 信网中心oracle数据库	 */
	@Bean(name = "dataSourceThimis")
	@ConfigurationProperties("spring.datasource.druid.oracle-thimis")
	public DataSource dataSourceThimis() {
		return DruidDataSourceBuilder.create().build();
	}
	
	/** 数据查询mysql数据库 */
	@Primary
	@Bean(name = "dataSourceDataAi")
	@ConfigurationProperties("spring.datasource.druid.data-ai")
	public DataSource dataSourceDataAi() {
		return DruidDataSourceBuilder.create().build();
	}
	
	/** 车辆备案、进出数据库 */
	@Bean(name = "dataSourceCarEnter")
	@ConfigurationProperties("spring.datasource.druid.car-enter")
	public DataSource dataSourceCarEnter() {
		return DruidDataSourceBuilder.create().build();
	}
	

	/** 访客申请数据库 */
	@Bean(name = "dataSourcePersonEnterApply")
	@ConfigurationProperties("spring.datasource.druid.person-enter-apply")
	public DataSource dataSourcePersonEnterApply() {
		return DruidDataSourceBuilder.create().build();
	}
	
	/** 人员进出数据库 */
	@Bean(name = "dataSourcePersonVisitLog")
	@ConfigurationProperties("spring.datasource.druid.person-visit-log")
	public DataSource dataSourcePersonVisitLog() {
		return DruidDataSourceBuilder.create().build();
	}
	
	/** 人员入校 申请数据库 */
	@Bean(name = "dataSourcePersonVisitApply")
	@ConfigurationProperties("spring.datasource.druid.person-visit-apply")
	public DataSource dataSourcePersonVisitApply() {
		return DruidDataSourceBuilder.create().build();
	}
	
	

	@Bean(name = "jdbcTemplateOA")
	public JdbcTemplate jdbcTemplateOA(@Qualifier("dataSourceOA")DataSource dataSourceOA) {
		return new JdbcTemplate(dataSourceOA);
	}

	@Bean(name = "jdbcTemplateThimis")
	public JdbcTemplate jdbcTemplateThimis(@Qualifier("dataSourceThimis") DataSource dataSourceThimis) {
		return new JdbcTemplate(dataSourceThimis);
	}
	
	@Bean(name = "jdbcTemplateDataAi")
	public JdbcTemplate jdbcTemplateDataAi(@Qualifier("dataSourceDataAi") DataSource dataSourceDataAi) {
		return new JdbcTemplate(dataSourceDataAi);
	}
	
	@Bean(name = "jdbcTemplatePersonVisit")
	public JdbcTemplate jdbcTemplatePersonVisit(@Qualifier("dataSourcePersonVisitLog") DataSource dataSourceDataAi) {
		return new JdbcTemplate(dataSourceDataAi);
	}
	
	@Bean(name = "jdbcTemplatePersonVisitApply")
	public JdbcTemplate jdbcTemplatePersonVisitApply(@Qualifier("dataSourcePersonEnterApply") DataSource datasource) {
		return new JdbcTemplate(datasource);
	}
	
	@Bean(name = "jdbcTemplateCarEnter")
	public JdbcTemplate jdbcTemplateCarEnter(@Qualifier("dataSourceCarEnter") DataSource datasource) {
		return new JdbcTemplate(datasource);
	}
	
	
	@Bean(name = "enhancedJdbcTemplateDataAi")
	public EnhancedJdbcTemplate enhancedJdbcTemplateDataAi(@Qualifier("dataSourceDataAi") DataSource dataSourceDataAi) {
		return new EnhancedJdbcTemplate(dataSourceDataAi);
	}
	
	@Bean(name = "enhancedJdbcTemplateThimis")
	public EnhancedJdbcTemplate enhancedJdbcTemplateThimis(@Qualifier("dataSourceThimis") DataSource dataSourceThimis) {
		return new EnhancedJdbcTemplate(dataSourceThimis);
	}
	
	
	
	@Bean
	public DataSourceTransactionManager transactionManager(@Qualifier("dataSourceDataAi") DataSource dataSourceDataAi) {
		return new DataSourceTransactionManager(dataSourceDataAi);
	}

}
